<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>send message page</title>
</head>
<body>
	<script type="text/javascript" src="http://cdn.bootcss.com/jquery/3.1.0/jquery.min.js"></script>
	<script type="text/javascript" src="http://cdn.bootcss.com/sockjs-client/1.1.1/sockjs.js"></script>
	<script type="text/javascript">
	var websocket = null;
    if ('WebSocket' in window) {
        websocket = new WebSocket("ws://localhost:8080/websocket-spring/websocket/socketServer");
    } else if ('MozWebSocket' in window) {
        websocket = new MozWebSocket("ws://localhost:8080/websocket-spring/websocket/socketServer");
    } else {
        websocket = new SockJS("http://localhost:8080/websocket-spring/sockjs/socketServer");
    }
    websocket.onopen = function(evnt) {
    	console.log("websocket连接上");
    };
    websocket.onmessage = function(evnt) {
    	console.log("server message:" + evnt.data);
    };
    websocket.onerror = function() {
    	console.log("server cause an error");
    };
    websocket.onclose = function() {
    	console.log("server close");
    };
    
    function doSend() {
        if (websocket.readyState == websocket.OPEN) {          
            var msg = document.getElementById("inputMsg").value;  
            websocket.send(msg);//调用后台handleTextMessage方法
            alert("发送成功!");  
        } else {  
            alert("连接失败!");  
        }  
    }
    window.close=function() {
    	websocket.onclose();
    }
	</script>
	请输入：<textarea rows="5" cols="10" id="inputMsg" name="inputMsg"></textarea>
	<button onclick="doSend();">发送</button><br/>
	<a href="send?username=lisen">测试一下</a>
</body>
</html>